<template>
  <div>
    <NavBack title="基本信息"></NavBack>

    <van-form @submit="submitForm">
      <van-field label="昵称：" v-model="form.nickname" value="32" placeholder="请输入昵称"
                 :rules="[{required:true}]"></van-field>
      <van-field label="姓名：" v-model="form.true_name" placeholder="请输入姓名"
                 :rules="[{required:true}]"></van-field>
      <van-field label="手机号：" v-model="form.phone" placeholder="请输入手机号"
                 :rules="[{required:true}]"></van-field>
      <van-field label="邮箱：" v-model="form.email" placeholder="请输入邮箱"
                 :rules="[{required:true}]"></van-field>
      <van-field label="学号：" v-model="form.student_number" placeholder="请输入学号"
                 :rules="[{required:true}]"></van-field>
      <van-field label="班级" v-model="form.classs" placeholder="请输入班级" :rules="[{required:true}]"></van-field>

      <div style="margin: 1rem;">
        <van-button round block type="info" native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import NavBack from "../common/NavBack";
import {status, user} from "../../request/api";

export default {
  name: "Info",
  data() {
    return {form: {}};
  },
  components: {NavBack},
  created() {
    let user = JSON.parse(localStorage.getItem('ba_user'));
    this.form = {
      nickname: user.nickname,
      true_name: user.true_name,
      phone: user.phone,
      email: user.email,
      student_number: user.student_number,
      classs: user.classs
    };
  },
  methods: {
    pageBack() {
      this.$router.go(-1);
    },
    async submitForm() {
      const res = await user.updateInfo(this.form);
      if (res.data.code == status.STATUS_SUCCESS) {
        this.$notify({type: 'success', message: res.data.msg});
        setTimeout(() => this.$router.back(), 2000);
      }
    },
  }
}
</script>

<style scoped>

</style>
